package com.cy.pj.notice.web.pojo;

public class JsonResult {
    /**
     * 基于此对象，封装服务端响应到客户端的数据
     * 1）状态码
     * 2）消息
     * 3）数据
     */
    //状态码
    private Integer state = 1;//1正常，0异常
    //状态信息
    private String message;
    //相应数据，一般为查询响应结果
    private Object data;

    //构造方法
    public JsonResult(Object data) {
        this.data = data;
    }

    public JsonResult(String message) {
        this.message = message;
    }

    public JsonResult(String message, Object data) {
        this.message = message;
        this.data = data;
    }

    public JsonResult(Throwable e) {//异常时使用
        this.state = 0;
        this.message = e.getMessage();
    }

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "JsonResult{" +
                "state=" + state +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
